package com.dgshanger.sanhxiaofeisc

import android.content.Context
import android.support.multidex.MultiDex
import android.support.multidex.MultiDexApplication
import cn.jpush.android.api.JPushInterface
import com.antiphon.paysdk.AntiphonPaySDK
import com.antiphon.paysdk.WeChatAppIDProvider
import com.blankj.utilcode.util.Utils
import com.dgshanger.sanhxiaofeisc.common.MyLifecycleHandler
import com.dgshanger.sanhxiaofeisc.ui.home.utils.LocationManger
import com.facebook.stetho.Stetho
import com.tencent.bugly.crashreport.CrashReport
import com.tencent.smtt.sdk.QbSdk
import com.umeng.commonsdk.UMConfigure
import com.umeng.socialize.PlatformConfig
import com.xx.baseutilslibrary.network.provider.JApiConfigProvider
import com.xx.baseutilslibrary.network.retrofit.Retrofit2Manager


/**
 * App
 * 沉迷学习不能自拔
 * Describe：
 * Created by 雷小星🍀 on 2018/4/12 11:38.
 */
class App : MultiDexApplication() {

    companion object {
        lateinit var application: App
            private set
    }

    override fun attachBaseContext(base: Context) {
        super.attachBaseContext(base)
        MultiDex.install(this)
    }

    override fun onCreate() {
        super.onCreate()
        application = this

        val cb = object : QbSdk.PreInitCallback {

            override fun onViewInitFinished(arg0: Boolean) {
                //x5內核初始化完成的回调，为true表示x5内核加载成功，否则表示x5内核加载失败，会自动切换到系统内核。
            }

            override fun onCoreInitFinished() {
            }
        }
        //x5内核初始化接口
        QbSdk.initX5Environment(applicationContext, cb)

        //腾讯bugly注册
        CrashReport.initCrashReport(getApplicationContext(), "96c1a69de3", false)

        //极光推送
        JPushInterface.setDebugMode(BuildConfig.DEBUG)
        JPushInterface.init(this)
        //
        Stetho.initializeWithDefaults(this)

        //初始化友盟
        UMConfigure.init(this, "5af105248f4a9d6df300028a"
                , "umeng", UMConfigure.DEVICE_TYPE_PHONE, "")
        PlatformConfig.setWeixin("wxd08a9b205494c248", "35c0bcca128270bd9b7ec01812fc97fa")
        PlatformConfig.setSinaWeibo("4285643628", "0dcfdb9213e48fb0bfd8f7479f208bf8", "http:www.baidu.com")
        PlatformConfig.setQQZone("1106602798", "gDWIr2lY4PT4OIVa")

        LocationManger.getInstance().init(this)//初始化百度定位管理器

        //自定义支付SDK设置
        AntiphonPaySDK.getIntance().init(this)
        AntiphonPaySDK.getIntance().weChatAppIDProvider = WeChatAppIDProvider { "wxd08a9b205494c248" }

        Utils.init(this)
        LocationManger.getInstance().init(this)

        //全局监听前后台
        registerActivityLifecycleCallbacks(MyLifecycleHandler())

        Retrofit2Manager.instance.apiConfigProvider = object : JApiConfigProvider {

            override fun getApiRelativePath(): String = "/api/"

            override fun getDebugHost(): String = "http://hhh.ljzchris.cn"

            override fun getReleaseHost(): String = "http://api.zg3h.com"

            override fun isDebug(): Boolean = BuildConfig.DEBUG
        }
    }
}